#-------------------------------------------------------------------
# Project Invasion of the aliens 
# name game.py
# purpose an enamy that goes it random directions and can kill players and other enemys 
#
# authors Chris L'Heureux, Tyler Plante, Jackson Morse
# main author Jackson Morse
#
# created 12/3/12
# Copyright (C) Jackson Morse 
# License New BSD\
#------------------------------------------------------------------  
import pygame, math, sys, random

class Enemy2():
    def __init__(self, position):
        self.surfaces = []
        self.surfaces += [pygame.image.load("images/Enemy/enemy2.png")]
        self.surfaces += [pygame.image.load("images/Enemy/enemy2.png")]
        self.frame = 0
        self.maxFrame = len(self.surfaces)-1
        self.surface = self.surfaces[self.frame]
        print str(self.surface)
        self.rect = self.surface.get_rect()
        self.radius = (self.rect.width/2 +self.rect.height/2)/2
        self.speed = [random.randint(-1,1),1]
        self.place(position)
        self.attack = 5
        self.health = 100
        self.living = True
        
        
    def  __str__(self):
        return "I'm an enemy!" + str(self.rect.center)
        
    def place(self, position):
        self.rect.center = position
        
    def move(self):
        #print "I've moved", self.speed
        self.rect = self.rect.move(self.speed)
     
    def collideWall(self, screenWidth, screenHeight):
        if (self.rect.left < 0 or self.rect.right > screenWidth):
                self.living = False 
        if (self.rect.top < 0 or self.rect.top > screenHeight):
                self.living = False
    
    def direction(self, dir):
        #print "moving in direction"
        return dir
        self.rect.move = player.rect.center(self.dir)
        
    def die(self):
        self.living = False

    
    def distToPoint(self, pt):
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))
                            

    
    def collidePlayer(self, player):
        if (self.rect.right > player.rect.left 
            and self.rect.left < player.rect.right):
            if (self.rect.bottom > player.rect.top and 
                self.rect.top < player.rect.bottom):
                if (self.distToPoint(player.rect.center)
                    < self.radius + player.radius):                 
                    player.die()
                    self.die()
                    
                    
    def collideEnemy(self, other):
        if (self.rect.right > other.rect.left 
            and self.rect.left < other.rect.right):
            if (self.rect.bottom > other.rect.top and 
                self.rect.top < other.rect.bottom):
                if (self.distToPoint(other.rect.center)
                    < self.radius + other.radius):
                    self.die()
                    other.die()
                    #TEST
                    
                    
    
  